<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="website">
<meta property="og:title" content="凌浩雨_博客">
<meta property="og:url" content="http://yoursite.com/blog/page/20/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发">
<meta property="og:locale" content="default">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="凌浩雨_博客">
<meta name="twitter:description" content="专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/page/20/"/>





  <title>凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-Social(社会化分享)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-Social(社会化分享)/" itemprop="url">iOS-Social(社会化分享)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>####1. 导包<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;Social/Social.h&gt;</span><br></pre></td></tr></table></figure></p>
<p>####2. 绑定账号<br>1). 系统语言要切换为中文。切换方法：Settings-&gt;General-&gt;Language &amp; Region-&gt;iPhone Language-&gt;简体中文-&gt;Done-&gt;Change to Simplified Chinese.<br>2). 新浪微博账号绑定。绑定方法：设置-&gt;新浪微博，输入账号和密码，点击登录即可成功绑定。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-a68c3ca84444658f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1.png"><br>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/2018/08/06/iOS-Special-Function/iOS-Social(社会化分享)/#more" rel="contents">
              Read more &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-Safari(浏览器)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-Safari(浏览器)/" itemprop="url">iOS-Safari(浏览器)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####开启系统浏览器<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line">#import &lt;SafariServices/SafariServices.h&gt;</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event</span><br><span class="line">&#123;</span><br><span class="line">    // 如果公司没有特殊的界面制定要求, 当弹出网页的时候, 可以使用这里的SFSafariViewController</span><br><span class="line">    SFSafariViewController *sf = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@&quot;https://www.baidu.com&quot;]];</span><br><span class="line">    [self presentViewController:sf animated:YES completion:nil];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-RegularExpression(正则表达式)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-RegularExpression(正则表达式)/" itemprop="url">iOS-RegularExpression(正则表达式)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####正则表达式<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> []    : 括号内方的是匹配的条件 , 一般来说, 一个[], 就代表匹配一位</span><br><span class="line"> [a-z] : 匹配小写 a~z</span><br><span class="line"> [0-9] : 匹配0~9的数字   另外一种写法 \d == [0-9]</span><br><span class="line"> ^     : 代表已后面的匹配条件为开头</span><br><span class="line"> $     : 代表以前面一个匹配条件为结果</span><br><span class="line"> &#123;&#125;    : 里面写的是查询次数的条件  &#123;4,9&#125;最少4次, 最多9次  / &#123;4,&#125;最少4此, 最多不限</span><br><span class="line"> ^[^0-9]: ^写在[]内, 就代表不能以括号内的条件作为开头</span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    //1. 获取一个要匹配的字符串</span><br><span class="line">    NSString *URLStr = @&quot;1234324&quot;;</span><br><span class="line"></span><br><span class="line">    //2. Pattern : 正则表达式语句 (语法规则)</span><br><span class="line">    NSString *pattern = @&quot;^[1-9][0-9]&#123;4,11&#125;$&quot;;</span><br><span class="line">    </span><br><span class="line">    //3. 创建正则表达式对象</span><br><span class="line">    //NSRegularExpression 正则表达式对象</span><br><span class="line">    //NSRegularExpressionCaseInsensitive: 忽略大小写</span><br><span class="line">    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];</span><br><span class="line">    </span><br><span class="line">    //4. 匹配</span><br><span class="line">    // 只匹配一次</span><br><span class="line">    //regex firstMatchInString:&lt;#(nonnull NSString *)#&gt; options:&lt;#(NSMatchingOptions)#&gt; range:&lt;#(NSRange)#&gt;</span><br><span class="line">    </span><br><span class="line">    // 匹配多次结果</span><br><span class="line">    //matchesInString: 需要匹配的字符串</span><br><span class="line">    //options: NSMatchingReportCompletion 一般使用这个, 匹配到了就会返回结果</span><br><span class="line">    //range : 范围</span><br><span class="line">    NSArray *resultArray = [regex matchesInString:URLStr options:NSMatchingReportCompletion range:NSMakeRange(0, URLStr.length)];</span><br><span class="line">    </span><br><span class="line">    //5. 获取匹配到的数据</span><br><span class="line">    if (resultArray.count) &#123;</span><br><span class="line">        // 匹配到了结果</span><br><span class="line">        NSLog(@&quot;匹配到了结果, 有% ld 个&quot;, resultArray.count);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        // 没有匹配到结果</span><br><span class="line">        NSLog(@&quot;没有匹配的结果&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-QRCode(二维码)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-QRCode(二维码)/" itemprop="url">iOS-QRCode(二维码)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>####实现思路</p>
<ol>
<li>输入设备(用来获取外界信息)  摄像头, 麦克风, 键盘</li>
<li>输出设备 (将收集到的信息, 做解析, 来获取收到的内容)</li>
<li>会话session (用来连接输入和输出设备)</li>
<li>特殊的layer (展示输入设备所采集的信息)<br>####1. 导包<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;AVFoundation/AVFoundation.h&gt;</span><br></pre></td></tr></table></figure>
</li>
</ol>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/2018/08/06/iOS-Special-Function/iOS-QRCode(二维码)/#more" rel="contents">
              Read more &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-Notification(本地通知)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-Notification(本地通知)/" itemprop="url">iOS-Notification(本地通知)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line"></span><br><span class="line">@interface ViewController ()</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    // Do any additional setup after loading the view, typically from a nib.</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> // 触发时间</span><br><span class="line"> @property(nullable, nonatomic,copy) NSDate *fireDate;</span><br><span class="line"> // 时区</span><br><span class="line"> @property(nullable, nonatomic,copy) NSTimeZone *timeZone;</span><br><span class="line"> </span><br><span class="line"> // 重复 --&gt; 单位是日历组件 , 0 代表不重复</span><br><span class="line"> @property(nonatomic) NSCalendarUnit repeatInterval;</span><br><span class="line"> </span><br><span class="line"> // 重复 --&gt; 上面那个属性所依赖的日历格式  公历 农历</span><br><span class="line"> @property(nullable, nonatomic,copy) NSCalendar *repeatCalendar;</span><br><span class="line"> </span><br><span class="line"> // 区域</span><br><span class="line"> @property(nullable, nonatomic,copy) CLRegion *region NS_AVAILABLE_IOS(8_0);</span><br><span class="line"> </span><br><span class="line"> // 区域只检测一次</span><br><span class="line"> @property(nonatomic,assign) BOOL regionTriggersOnce NS_AVAILABLE_IOS(8_0);</span><br><span class="line"> </span><br><span class="line"> // 提醒的主题内容</span><br><span class="line"> @property(nullable, nonatomic,copy) NSString *alertBody;   </span><br><span class="line"> </span><br><span class="line"> // 是否显示锁屏时的文字以及提醒样式的按钮文字</span><br><span class="line"> @property(nonatomic) BOOL hasAction;  </span><br><span class="line"> </span><br><span class="line"> // 设置显示锁屏时的文字以及提醒样式的按钮文字</span><br><span class="line"> @property(nullable, nonatomic,copy) NSString *alertAction; </span><br><span class="line"> </span><br><span class="line"> // 设置启动图</span><br><span class="line"> @property(nullable, nonatomic,copy) NSString *alertLaunchImage; </span><br><span class="line"> </span><br><span class="line"> // 设置标题</span><br><span class="line"> @property(nullable, nonatomic,copy) NSString *alertTitle</span><br><span class="line"> </span><br><span class="line"> // 设置声音 , 默认声音: UILocalNotificationDefaultSoundName</span><br><span class="line"> @property(nullable, nonatomic,copy) NSString *soundName;</span><br><span class="line"> </span><br><span class="line"> // 设置图标的数字角标 (图标标记)</span><br><span class="line"> @property(nonatomic) NSInteger applicationIconBadgeNumber;  // 0 means no change. defaults to 0</span><br><span class="line"> </span><br><span class="line"> // 设置携带参数</span><br><span class="line"> @property(nullable, nonatomic,copy) NSDictionary *userInfo;</span><br><span class="line"> </span><br><span class="line"> // 设置分类</span><br><span class="line"> @property (nullable, nonatomic, copy) NSString *category</span><br><span class="line"></span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark 点击发送本地通知</span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event</span><br><span class="line">&#123;</span><br><span class="line">    //1. 创建本地通知对象</span><br><span class="line">    UILocalNotification *localNotifi = [UILocalNotification new];</span><br><span class="line">    </span><br><span class="line">    //2. 设置属性</span><br><span class="line">    </span><br><span class="line">    //2.1 设置触发时间</span><br><span class="line">    localNotifi.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];</span><br><span class="line">    </span><br><span class="line">    //2.2 设置提示内容</span><br><span class="line">    localNotifi.alertBody = @&quot;今天不适合敲代码&quot;;</span><br><span class="line">    </span><br><span class="line">    //2.3 设置声音 (只有真机有效)</span><br><span class="line">    localNotifi.soundName = UILocalNotificationDefaultSoundName;</span><br><span class="line">    </span><br><span class="line">    localNotifi.applicationIconBadgeNumber = 5;</span><br><span class="line">    </span><br><span class="line">    //2.4 设置 默认YES</span><br><span class="line">    localNotifi.hasAction = NO;</span><br><span class="line">    </span><br><span class="line">    //2.5 设置 提醒样式的按钮文字 / 锁屏界面底部的文字</span><br><span class="line">    localNotifi.alertAction = @&quot;回复呵呵&quot;;</span><br><span class="line">    </span><br><span class="line"> #pragma mark 不常用属性</span><br><span class="line">    </span><br><span class="line">    //2.6 设置重复 最小单位是分钟 如果此属性设置了, 那么调度池不会用完释放</span><br><span class="line">    //localNotifi.repeatInterval = NSCalendarUnitMinute;</span><br><span class="line">    </span><br><span class="line">    //2.7 设置重复所依赖的日历 不设置的话, 默认是跟随系统设置走得</span><br><span class="line">    </span><br><span class="line">    // 默认就是跟随系统走</span><br><span class="line">    //localNotifi.repeatCalendar = [NSCalendar calendarWithIdentifier:@&quot;跳进官方文档, 里面就有一堆的标示符, 找chinese的选项, 就代表是农历&quot;];</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    //3. 调度通知 , 如果是IOS7 , 这一步写完就OK</span><br><span class="line">    //schedule : 调度</span><br><span class="line">    // 将通知加入到本地调度池中</span><br><span class="line">    [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi];</span><br><span class="line">    </span><br><span class="line">    //4. iOS8 需要增加一个方法 --&gt; 需要授权</span><br><span class="line">    </span><br><span class="line">    /**</span><br><span class="line">     UIUserNotificationTypeNone    = 0,</span><br><span class="line">     UIUserNotificationTypeBadge   = 1 &lt;&lt; 0, //图标标记</span><br><span class="line">     UIUserNotificationTypeSound   = 1 &lt;&lt; 1, //声音</span><br><span class="line">     UIUserNotificationTypeAlert   = 1 &lt;&lt; 2, //提醒</span><br><span class="line">     */</span><br><span class="line">    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];</span><br><span class="line">    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];</span><br><span class="line">    </span><br><span class="line">    //5. 删除通知</span><br><span class="line">    // 删除当前程序注册的所有通知</span><br><span class="line">    [[UIApplication sharedApplication] cancelAllLocalNotifications];</span><br><span class="line">    </span><br><span class="line">    // 删除指定的通知 --&gt; 一般用于干掉会重复的通知 / 或者还没有被调用的通知</span><br><span class="line">    //[[UIApplication sharedApplication] cancelLocalNotification:localNotifi];</span><br><span class="line">    </span><br><span class="line">    // 获取通知 --&gt; 配合删除用的</span><br><span class="line">    NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];</span><br><span class="line">    for (UILocalNotification *local in localNotifications) &#123;</span><br><span class="line">        NSLog(@&quot;local: %@&quot;, local);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    // 如果是当前程序内收到了通知, 那么界面没有任何变化</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-Motion(传感器)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-Motion(传感器)/" itemprop="url">iOS-Motion(传感器)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>####1. 距离传感器<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    //1. 开启距离传感器</span><br><span class="line">    [UIDevice currentDevice].proximityMonitoringEnabled = YES;</span><br><span class="line">    </span><br><span class="line">    //2. 注册通知</span><br><span class="line">    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChangeNotification) name:UIDeviceProximityStateDidChangeNotification object:nil];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark 通知的方法</span><br><span class="line">- (void)proximityStateDidChangeNotification &#123;</span><br><span class="line">    //3. 获取通知的值</span><br><span class="line">    if ([UIDevice currentDevice].proximityState) &#123;</span><br><span class="line">        NSLog(@&quot;有逗比靠近&quot;);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        NSLog(@&quot;逗比被吓跑了&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/2018/08/06/iOS-Special-Function/iOS-Motion(传感器)/#more" rel="contents">
              Read more &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-MapView(定位)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-MapView(定位)/" itemprop="url">iOS-MapView(定位)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>####1. 实现一次定位<br>1). 导入头文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;CoreLocation/CoreLocation.h&gt;</span><br></pre></td></tr></table></figure></p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/2018/08/06/iOS-Special-Function/iOS-MapView(定位)/#more" rel="contents">
              Read more &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-LocalAuthentication(指纹识别)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-LocalAuthentication(指纹识别)/" itemprop="url">iOS-LocalAuthentication(指纹识别)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####指纹识别<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line">#import &lt;LocalAuthentication/LocalAuthentication.h&gt;</span><br><span class="line"></span><br><span class="line">@interface ViewController ()</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event</span><br><span class="line">&#123;</span><br><span class="line">    //1. 判断系统版本</span><br><span class="line">    if ([UIDevice currentDevice].systemVersion.floatValue &gt;= 8.0) &#123;</span><br><span class="line">        //可以使用指纹识别 --&gt; 5S 以后的机型</span><br><span class="line">        </span><br><span class="line">        //2. 判断时候可以使用指纹识别功能</span><br><span class="line">        </span><br><span class="line">        //2.1 创建 LA 对象上下文</span><br><span class="line">        LAContext *context = [[LAContext alloc] init];</span><br><span class="line">        </span><br><span class="line">        //2.2 判断是否能否使用</span><br><span class="line">        //Evaluate: 评估</span><br><span class="line">        //Policy: 策略</span><br><span class="line">        //LAPolicyDeviceOwnerAuthenticationWithBiometrics : 可以使用指纹识别技术</span><br><span class="line">        if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) &#123;</span><br><span class="line">            // 可以使用</span><br><span class="line">            </span><br><span class="line">            //3. 开始启用指纹识别</span><br><span class="line">            //localizedReason : 显示在界面上的原因, 一般用于提示用户, 为什么要使用此功能</span><br><span class="line">            [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@&quot;请验证指纹, 以打开高级隐藏功能&quot; reply:^(BOOL success, NSError * _Nullable error) &#123;</span><br><span class="line">                </span><br><span class="line">                //判断是否成功</span><br><span class="line">                if (success) &#123;</span><br><span class="line">                    </span><br><span class="line">                    </span><br><span class="line">                    //4. 指纹识别在更新 UI 时, 一定要注意, 在主线程更新</span><br><span class="line">                    </span><br><span class="line">                    dispatch_sync(dispatch_get_main_queue(), ^&#123;</span><br><span class="line">                        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@&quot;这是标题&quot; message:@&quot;你成功了&quot; delegate:nil cancelButtonTitle:@&quot;取消&quot; otherButtonTitles:nil];</span><br><span class="line">                        </span><br><span class="line">                        [alert show];</span><br><span class="line">                    &#125;);</span><br><span class="line">                    </span><br><span class="line">                &#125; else &#123;</span><br><span class="line">                    </span><br><span class="line">                    dispatch_sync(dispatch_get_main_queue(), ^&#123;</span><br><span class="line">                        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@&quot;这是标题&quot; message:@&quot;验证失败&quot; delegate:nil cancelButtonTitle:@&quot;取消&quot; otherButtonTitles:nil];</span><br><span class="line">                        </span><br><span class="line">                        [alert show];</span><br><span class="line">                        </span><br><span class="line">                    &#125;);</span><br><span class="line">                &#125;</span><br><span class="line">                </span><br><span class="line">                // 判断错误 如果需要区分不同的错误来提示用于, 必须判断 error, -1, -2, -8</span><br><span class="line">                if (error) &#123;</span><br><span class="line">                    NSLog(@&quot;error Code: %ld&quot;,error.code);</span><br><span class="line">                    NSLog(@&quot;error : %@&quot;,error.userInfo);</span><br><span class="line">                &#125;</span><br><span class="line">                </span><br><span class="line">            &#125;];</span><br><span class="line">            </span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            NSLog(@&quot;对不起, 5S 以上机型才能使用此功能, 请卖肾后重拾&quot;);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        NSLog(@&quot;对不起, 系统版本过低&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-DynamicAnimator(物理仿真)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-DynamicAnimator(物理仿真)/" itemprop="url">iOS-DynamicAnimator(物理仿真)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####物理仿真<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line">@interface ViewController ()</span><br><span class="line">@property (weak, nonatomic) IBOutlet UIView *redView;</span><br><span class="line">@property (weak, nonatomic) IBOutlet UIView *blueView;</span><br><span class="line"></span><br><span class="line">/** 物理仿真器*/</span><br><span class="line">@property (strong, nonatomic) UIDynamicAnimator *animator;</span><br><span class="line"></span><br><span class="line">/** 捕捉行为*/</span><br><span class="line">@property (strong, nonatomic)  UISnapBehavior *snap;</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (UIDynamicAnimator *)animator</span><br><span class="line">&#123;</span><br><span class="line">    if (_animator == nil) &#123;</span><br><span class="line">        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];</span><br><span class="line">    &#125;</span><br><span class="line">    return _animator;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    //self.redView.transform = CGAffineTransformRotate(self.redView.transform, 40);</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark 点击屏幕开始重力和碰撞仿真行为</span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event</span><br><span class="line">&#123;</span><br><span class="line">    if (self.snap == nil) &#123;</span><br><span class="line">        // iOS8以前, 是无法更改point, 如果要更改, 需要移除并重新添加</span><br><span class="line">        //0. 获取点击的点</span><br><span class="line">        CGPoint point = [[touches anyObject] locationInView:self.view];</span><br><span class="line">        </span><br><span class="line">        //1. 添加snap之前, 需要移除之前的行为</span><br><span class="line">        </span><br><span class="line">        // 如果需要更改snapPoint, 此方法就不需要写了</span><br><span class="line">        //[self.animator removeAllBehaviors];</span><br><span class="line">        </span><br><span class="line">        //2. 创建物理仿真行为(顺便设置物理仿真元素)</span><br><span class="line">        // Point自行设置即可</span><br><span class="line">        self.snap = [[UISnapBehavior alloc] initWithItem:self.redView snapToPoint:point];</span><br><span class="line">        </span><br><span class="line">        //2.1 设置 振幅 减震效果  0最大, 1最小</span><br><span class="line">        self.snap.damping = 0.5;</span><br><span class="line">        </span><br><span class="line">        //3. 将仿真行为添加到仿真器中</span><br><span class="line">        [self.animator addBehavior:self.snap];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    //2.2 设置位置</span><br><span class="line">    static int i = 1;</span><br><span class="line">    self.snap.snapPoint = CGPointMake(200, 50 * i);</span><br><span class="line">    i++;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">//点击屏幕开始重力+碰撞仿真行为</span><br><span class="line">- (void)gravityAndCollision</span><br><span class="line">&#123;</span><br><span class="line">    //1. 创建物理仿真器(顺便设置仿真范围)</span><br><span class="line">    self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];</span><br><span class="line">    </span><br><span class="line">    //2. 创建物理仿真行为(顺便设置物理仿真元素)</span><br><span class="line">    UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.redView]];</span><br><span class="line">    </span><br><span class="line">    //2.1 向量, 重力方向</span><br><span class="line">    gravity.gravityDirection = CGVectorMake(3, 1);</span><br><span class="line">    </span><br><span class="line">    //2.2 角度 默认就是90°, M_PI_2</span><br><span class="line">    gravity.angle = M_PI_2;</span><br><span class="line">    </span><br><span class="line">    //2.3 重力加速度 越小越慢</span><br><span class="line">    gravity.magnitude = 100;</span><br><span class="line">    </span><br><span class="line">    UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[self.redView, self.blueView]];</span><br><span class="line">    </span><br><span class="line">    // 设置参考引用的视图的边框为自己的边框</span><br><span class="line">    collision.translatesReferenceBoundsIntoBoundary = YES;</span><br><span class="line">    </span><br><span class="line">    // 设置碰撞的边界</span><br><span class="line">    //    CGPoint fromPoint = CGPointMake(0, [UIScreen mainScreen].bounds.size.height * 0.2);</span><br><span class="line">    //    CGPoint toPoint = CGPointMake(375, [UIScreen mainScreen].bounds.size.height * 0.8);</span><br><span class="line">    //    [collision addBoundaryWithIdentifier:@&quot;collision&quot; fromPoint:fromPoint toPoint:toPoint];</span><br><span class="line">    </span><br><span class="line">    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 375, 375)];</span><br><span class="line">    [collision addBoundaryWithIdentifier:@&quot;collision&quot; forPath:bezierPath];</span><br><span class="line">    </span><br><span class="line">    //3. 将仿真行为添加到仿真器中</span><br><span class="line">    [self.animator addBehavior:gravity];</span><br><span class="line">    [self.animator addBehavior:collision];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">//点击屏幕开始重力仿真行为</span><br><span class="line">- (void)gravity</span><br><span class="line">&#123;</span><br><span class="line">    //1. 创建物理仿真器(顺便设置仿真范围)</span><br><span class="line">    self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];</span><br><span class="line">    </span><br><span class="line">    //2. 创建物理仿真行为(顺便设置物理仿真元素)</span><br><span class="line">    UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.redView]];</span><br><span class="line">    </span><br><span class="line">    //3. 将仿真行为添加到仿真器中</span><br><span class="line">    [self.animator addBehavior:gravity];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/iOS-Special-Function/iOS-CoreData(数据库)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2018/08/06/iOS-Special-Function/iOS-CoreData(数据库)/" itemprop="url">iOS-CoreData(数据库)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>####1. 创建项目</p>
<p>####2. 创建CoreDataManager来管理<br>MTCoreDataManager.h文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;Foundation/Foundation.h&gt;</span><br><span class="line">#import &lt;CoreData/CoreData.h&gt;</span><br><span class="line">@interface MTCoreDataManager : NSObject</span><br><span class="line"></span><br><span class="line">// 创建一个管理对象上下文</span><br><span class="line">@property (nonatomic, strong) NSManagedObjectContext *managerContext;</span><br><span class="line"></span><br><span class="line">// 单例</span><br><span class="line">+ (instancetype)sharedManager;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/2018/08/06/iOS-Special-Function/iOS-CoreData(数据库)/#more" rel="contents">
              Read more &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/19/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/19/">19</a><span class="page-number current">20</span><a class="page-number" href="/blog/page/21/">21</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/40/">40</a><a class="extend next" rel="next" href="/blog/page/21/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
